﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Configuration;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using NLCER;

namespace NLServices
{
    partial class NLMailServices : ServiceBase
    {
        #region Constructor
        public NLMailServices()
        {
            InitializeComponent();
            this.ServiceName = "NLMailServices";
        }
        #endregion

        #region Field
        private static System.Timers.Timer _curtimer;
        #endregion

        #region process State
        protected override void OnStart(string[] args)
        {
            try
            {
                int icur = 600000;
                if (null == _curtimer)
                {
                    _curtimer = new System.Timers.Timer();
                    _curtimer.Elapsed += time_tick;
                }

                if (int.TryParse(ConfigurationManager.AppSettings["tskTick"], out icur))
                    _curtimer.Interval = icur;

                _curtimer.Start();
            }
            catch (Exception exp)
            {
                WinLog.Addlog(exp.Message, "NLMailServices");
            }
        }

        protected override void OnStop()
        {
            // TODO: Add code here to perform any tear-down necessary to stop your service.
        }
        #endregion

        #region Event
        /// <summary>
        /// Buildtsk
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void time_tick(object sender, EventArgs e)
        {
            try
            {
                //WinLog.Addlog("Processing Task List.", "NLMailServices");
                NLSMain.ProcessTsk();
                //WinLog.Addlog("End Process Task List.", "NLMailServices");
            }
            catch (Exception exp)
            {
                WinLog.Addlog(exp.Message, "NLMailServices");
            }           
        }
        #endregion
    }
}
